This invention relates generally to computer graphics systems, and, more particularly, to rendering shadows generated by computer graphics systems.
The entertainment and advertising industries have made computer-generated animations common place today in movie special effects and in commercials, respectively. In addition, games and visual simulations have also created consumer interest in realistic images and animations. Typically, in order to create realistic images and animations, a computer must generate a three-dimensional (3D) scene with various objects and then capture the effects of light interacting between each of the various objects. The computer then generates a new, slightly different two-dimensional (2D) view of the scene many times per second, thereby simulating movement and interaction of the various objects. The computer generation of new, slightly different views is commonly referred to as real time 3D graphics.
Typically, the computer generating multiple 2D graphic views in sequence includes specialized hardware usually referred to as a graphics display processor. The combination of an integrated computer with a display processor is commonly known as a graphics workstation. A graphics workstation runs a 3D graphics application that provides various techniques for simulating the movement and interaction of various objects. Simulating shadows caused by the interaction of the various objects is very desirable because shadows convey a large amount of information necessary for conveying the 3D nature of rendered objects and for adding realism to the computer generated sequence of 2D views. Therefore, a 3D graphics workstation typically provides a technique for generating shadows of 3D objects and rendering these objects along with their shadows onto a 2D view.
Various methods of rendering shadows have been proposed. Many of these methods are described in the publication xe2x80x9cComputer Graphics Principles and Practice, Second Edition in Cxe2x80x9d, Foley et al., Addison-Wesley Publishing Company, Inc., pp. 745-753. Examples of some computationally intense methods of rendering shadows are the two-pass z-buffer shadow method described in an article entitled xe2x80x9cCasting Curved Shadows on Curved Surfaces,xe2x80x9d Williams, L., Proceedings of SIGGRAPH ""78, pp. 270-274 which is also described on pp. 751-753 of the above mentioned publication and the shadow volume method described in an article entitled xe2x80x9cShadow Algorithms for Computer Graphics,xe2x80x9d Crow, F. C., Proceedings of SIGGRAPH ""77, pp. 442-448 which is also described on pp. 749 of above mentioned publication.
In general, the two-pass z-buffer method involves generating a z-buffer (a shadow map) for an image from a viewpoint of a light (a light coordinate system) with values in the z-buffer representing distances from the light to the object (i.e. closer objects will have a value indicating a higher intensity than farther away objects). A second pass generates a z-buffer for the image from the viewpoint of an observer (an observer coordinate system) using a well known z-buffer algorithm along with a modification that transforms a pixel""s observer coordinates into light coordinates whenever that pixel is determined to be visible. Therefore, computations for shadow calculations must be performed for each pixel even if the pixel is ultimately painted over by closer objects. In addition, computations for transforming an object coordinate to light coordinate for every pixel must be performed.
The shadow volume method involves the generation of a shadow volume determined by a volume that is blocked from a light source by an object. A point (or pixel) is then determined to be in shadow by assigning each front-facing shadow polygon a value of +1 and each back-facing shadow polygon a value of xe2x88x921, and using a counter to increment or decrement accordingly to determine whether the point is in shadow. Because the shadow volume does not require any translation of coordinate systems, the method is fairly efficient to implement if the object is simple. However, if the object is a complex shape, the computation required to calculate the shadow volume becomes very complicated.
Because both the two-pass z-buffer and the shadow volume methods are computationally intense when employed to generate the shadows of complex shaped objects, neither method is desirable for real-time applications. As a result, other, less computationally intense, techniques have been developed. Unfortunately, these other techniques result in poorer quality views because of the introduction of undesirable artifacts. One such other technique is the shadow projection method described in the publication xe2x80x9cOpenGL Programming Guide, Second edition,xe2x80x9d Woo et al., Addison-Wesley Developers Press, pp. 519-521. In general, the shadow projection method uses a shadow projection matrix to find the shadow of an object on an arbitrary plane using an arbitrary light source. This method avoids the computations necessary to translate the coordinates of an object from one coordinate system to another coordinate system.
FIG. 1 illustrates a view generated using the shadow projection method. A teapot model 10 is shown creating a shadow 12 on a shadow plane 14 as a result of the teapot model 10 blocking simulated rays (not shown) from a light source 16. The computer represents the shape of the teapot model 10 by using several polygons (i.e. triangles) that approximate the surface of the teapot model 10, such as a spout polygon 20, a teapot body polygon 22 (and a teapot handle polygon, not viewable in FIG. 1). This modeling of an object is well known in the art and is referred to as polygon mesh or polygonal modeling.
To create the shadow 12, the shadow projection method first multiplies the world coordinates of each polygon representing the teapot model 10 with the shadow projection matrix shown below:                     [                  xe2x80x83                ⁢                                                                              b                  *                  dy                                +                                  c                  *                  dz                                                                                                      -                  a                                *                dy                                                                                      -                  a                                *                dz                                                    0                                                                                            -                  b                                *                dx                                                                                      a                  *                  dx                                +                                  c                  *                  dz                                                                                                      -                  b                                *                dz                                                    0                                                                                            -                  c                                *                dx                                                                                      -                  c                                *                dy                                                                                      a                  *                  dx                                +                                  b                  *                  dy                                                                    0                                                                                            -                  d                                *                dx                                                                                      -                  d                                *                dy                                                                                      -                  d                                *                dz                                                                                      a                  *                  dx                                +                                  b                  *                  dy                  *                  c                  *                  dz                                                                    ⁢                  xe2x80x83                ]                            (        1        )            
where a, b, c, and d are variable obtained from the equation of the shadow plane 14, ax+by+c+d=0, and dx, dy, and dz represent the distance from a point to the shadow plane 14. Multiplication by this matrix projects each polygon onto the shadow plane 14, thus projecting the teapot model 10 onto the shadow plane 14.
After projecting the teapot model 10 onto the shadow plane 14, the shadow projection method adjusts colors and textures of each polygon of the teapot model in relation to the objects that were shadowed. In the example shown, only the relation between the polygons of the teapot model itself is shown without showing any interaction of the tea pot model with other objects. This simplification more easily illustrates a disadvantage of using the shadow projection method for generating realistic images, as will be described below.
The adjustment of colors and textures for the teapot model 10 is accomplished by blending each polygon into- the scene. In general, blending is the linear combination of the color for two object""s pixels that overlap. Each object has associated alpha values that represent the color for each individual pixel of the object along with the degree of transparency. When two objects are blended, for each pixel that overlaps, one object is considered a top object and the other object is considered a bottom object. Blending results in any pixel whose top object pixel alpha value is non-transparent, taking on the top object""s pixel color. Blending results in a linear combination of both the top and bottom objects"" pixel color when the top object pixel alpha value has any degree of transparency. Typically, a polygon covers several pixels selected so that each pixel""s alpha value representing the color and transparency are the same. Therefore, the alpha value of each polygon represents the alpha value for each individual pixel in the associated polygon.
As a result, because each of the polygons have an alpha value designating some degree of transparency, the resultant teapot shadow will have darker areas where two or more polygons overlapped and the overlapped pixels were linearly blended. Such darker areas, shown generally at 25 and 26, are visual artifacts generated by the shadow projection method and are not desirable because the darker areas destroy the realism of the image. These darker areas will occur even when back-face culling is performed. Another disadvantage of the shadow projection method is the inefficiency of clipping the resultant shadow along the edge of an object. This is due to the necessity of clipping each polygram (i.e., thousands of triangles) representing the model.
Therefore, there is a need for a 3D graphics shadow generation method that produces shadows in real time without producing an image whose quality is compromised by less intense computations or other means. The invention is directed to filling this need.
In accordance with this invention a method, a computer-readable medium, and a system for generating a shadow for a three dimensional model illuminated by a light source are provided. A projected shadow model and a projected bounding area of the model are found on a shadow plane. A screen extent is found that completely encompasses the projected bounding area. Then, once a texture map is prepared, the projected shadow model is rendered onto the texture map creating a projected shadow texture map. After the projected bounding area is prepared, the projected shadow texture map is rendered onto the projected bounding area creating a shadow texture mapped bounding area. This shadow texture mapped bounding area is then rendered into a scene. The scene with the rendered shadow texture mapped bounding area is displayed.
In accordance with further aspects of this invention, finding a projected shadow model on a shadow plane includes disabling a blended transparency option; applying a shadow projection matrix to the model that projects a shadow of the model onto the shadow plane; setting a color attribute for the projected shadow model to correspond to a desired shadow color; and setting a texture attribute for the projected shadow model to correspond to a desired shadow texture.
In accordance with other aspects of this invention, finding a projected bounding area on the shadow plane includes: finding a three-dimensional (3D) bounding volume of the model; applying a shadow projection matrix to the 3D bounding volume that projects the 3D bounding volume onto the shadow plane creating the projected bounding area; applying a view transformation to the projected bounding area; and clipping the projected bounding area against a view frustum.
In accordance with yet further aspects of this invention, preparing a texture map includes: creating the texture map with a size based on the screen extent; clearing the texture map to a non-shadow color; and setting an option that removes the non-shadow color when the texture map is rendered.
In accordance with still other aspects of this invention, preparing the projected bounding area includes: setting each vertex of the projected bounding area to a shadow alpha value; setting each vertex""s texture coordinates of the projected bounding area to evenly map the texture map; disabling a perspective texture correction option; and enabling a blended transparency option.
As will be readily appreciated from the foregoing summary, the invention provides a new and improved method, apparatus and computer-readable medium: for generating a shadow for a 3D model. Even though hardware performance may make the computationally intense methods described above more feasible in the future, the more efficient method of the present invention will continue to provide advantages over other, more computationally intense, methods. One reason is the increasing desire to make more complicated and realistic images which will necessitate using the most efficient method available for rendering shadows in both real time applications and non-real time applications. Another reason is that the majority of consumers will be unable to afford the higher end computers capable of using the computationally intense methods. Rather, there will be a need to provide xe2x80x9chigher endxe2x80x9d quality with more computationally efficient methods.